package com.bible.fire.util.webservice;

import java.util.LinkedHashMap;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.util.Log;

public class WebServiceHelper {
	
	private static String TAG = WebServiceHelper.class.getSimpleName();
	
	public static String callWebService( ServiceConnectParam scp,  LinkedHashMap<String, Object> paramMap ){
	    SoapObject rpc = new SoapObject(  scp.getNameSpace(),  scp.getMethodName() );
	    if( paramMap != null && paramMap.size() > 0 ){
	    	for ( String key : paramMap.keySet() ){			    	         
    	        rpc.addProperty( key,  paramMap.get(key) );
    	        Log.d("key", key + "=" + paramMap.get(key) );
	    	}
	    }
	    //soap协议版本号
	    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11 );                 
        envelope.bodyOut = rpc;  
        envelope.setOutputSoapObject(rpc);
        //android传输对象
	    HttpTransportSE  ht = new HttpTransportSE( scp.getUrl()   ); 
	    ht.debug = true;	    
	    try {		        
	    	ht.call( null, envelope );
	    	if( envelope.getResponse() != null ){
    		   Log.d("service resp", envelope.getResponse().toString());
    		   SoapObject result = (SoapObject)envelope.bodyIn;
    		   Log.d( TAG, result.toString() );	    		  
	    	}
	    	ht.getServiceConnection().disconnect();
		} catch (Exception e) {
			Log.e(TAG, "send ws error", e);
			e.printStackTrace();
		}	
	    return "";
	}
	
}
